<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>知识库新增</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<!-- jQuery-->
		<script type="text/javascript" src="/static/plugins/jquery/jquery-3.6.0.min.js"></script>

		<!-- layui-->
		<link rel="stylesheet" href="/static/plugins/layui/2.8.4/css/layui.css" media="all">
		<script src="/static/plugins/layui/2.8.4/layui.js" charset="utf-8"></script>
		
		
	</head>
	<style>
		.all-view{
			width: 90%;
			margin: 0 auto;
			margin-top: 20px;
		}
		.btn-view{
			margin-bottom: 10px;
			
		}
		.add-btn{
			width:120px;
		}
		.bottom-view{
			position: fixed;
			bottom: 0;
			width: 100%;
		}
		.add-btn-view{
			width: 260px;
			margin: 0 auto;
			margin-bottom: 40px;
		}
	</style>
	
	<body>
		
		<!--头部输入框-->
		
		<form class="layui-form layui-form-pane all-view" action="">
		
			<div class="layui-form-item">
				<label class="layui-form-label">知识库名称</label>
				<div class="layui-input-block">
				  <input type="text" name="knowledgeBaseName" id="knowledgeBaseName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" maxlength="10">
				</div>
			  </div>


			<div class="layui-form-item layui-form-text" >
				<label class="layui-form-label">知识库描述</label>
				<div class="layui-input-block">
				  <textarea placeholder="请输入内容" class="layui-textarea" id="knowledgeBaseDescribe" maxlength="100"></textarea>
				</div>
			  </div>
			  
			<div class="layui-form-item">
				<label class="layui-form-label">排序</label>
				<!--
				<div class="layui-input-block">
				  <input type="number" name="sort" id="sort" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
				</div>-->

				<div class="layui-input-block">
					<div style="float: left;margin-right: 5px;margin-left: 10px;">
						<button type="button" class="layui-btn layui-btn-sm" onclick="phaseNumDown()" style="height: 38px;">
							<i class="layui-icon layui-icon-subtraction"></i>
						</button>
					</div>
					<input type="number" name="sort" id="sort" autocomplete="off"
						   readonly="readonly"  class="layui-input" style="float: left;width: 200px;text-align: center;margin-right: 5px;" >
					<div style="float: left;">
						<button type="button" class="layui-btn layui-btn-sm" onclick="phaseNumAdd()" style="height: 38px;">
							<i class="layui-icon layui-icon-add-1"></i>
						</button>
					</div>
				</div>
			  </div>
			  
			  
			  
			 
		</form>
		
	
	<div class="bottom-view">
		<div class="layui-btn-container add-btn-view">
		  <button type="button" class="layui-btn layui-btn-primary layui-border-blue add-btn" onclick="saveChange();">确定</button>
		  <button type="button" class="layui-btn layui-btn-primary layui-border add-btn" onclick="cancelBtn();">取消</button>
		</div>
	</div>


        <input type="hidden" name="addOrUpdate" id="addOrUpdate" value=""><!--新增还是修改-->
        <input type="hidden" name="knowledgeBaseId" id="knowledgeBaseId" value=""><!--知识库id-->
		
		
		
		
	</body>
<script>
	$(function() {

		var addOrUpdate = '[(${dto.addOrUpdate})]';
		$('#addOrUpdate').val(addOrUpdate);
		if(addOrUpdate=='update'){
            $('#knowledgeBaseId').val('[(${dto.knowledgeBaseId})]');
			$.ajax({
				url : '/api/inter/knowledgeBase/searchKnowledgeBaseById',
				data : {id:$('#knowledgeBaseId').val()},
				type : 'POST',
				async : false,
				success : function(result) {
					if(result.code=='SUCCESS'){
						var eKnowKnowledgeBase = result.eKnowKnowledgeBase;
						if(eKnowKnowledgeBase!=null){
							$('#knowledgeBaseName').val(eKnowKnowledgeBase.knowledgeBaseName);
							$('#knowledgeBaseDescribe').val(eKnowKnowledgeBase.knowledgeBaseDescribe);
							$('#sort').val(eKnowKnowledgeBase.sort);

						}

					}else{
						layer.msg('不好意思，系统出现问题了，请稍后重试！', {icon: 2});
						setTimeout(function(){
							window.parent.layer.closeAll();
						}, 1000);
					}
				}
			});

        }else {
			$('#sort').val(1);
		}

	});

	//保存
	function saveChange() {
		var knowledgeBaseName = $('#knowledgeBaseName').val();
		var knowledgeBaseDescribe = $('#knowledgeBaseDescribe').val();
		var sort = $('#sort').val();
		if(knowledgeBaseName ==undefined || knowledgeBaseName ==null || knowledgeBaseName =='' ){
			layer.msg('请填写知识库名称', {icon: 0});
			return ;
		}
		if(knowledgeBaseDescribe ==undefined || knowledgeBaseDescribe ==null || knowledgeBaseDescribe =='' ){
			layer.msg('请填写知识库描述', {icon: 0});
			return ;
		}
		if(sort ==undefined || sort ==null || sort =='' ){
			layer.msg('请设置排序', {icon: 0});
			return ;
		}


		//layui.layer.msg('保存中', {icon: 16,shade: 0.01});
		layer.load(2);
		$.ajax({
			url: '/api/inter/knowledgeBase/addOrUpdateKnowledgeBase',
			data: {
				'addOrUpdate':$('#addOrUpdate').val(),
				'knowledgeBaseId':$('#knowledgeBaseId').val()==null?'':$('#knowledgeBaseId').val(),
				'knowledgeBaseName':$('#knowledgeBaseName').val(),
				'knowledgeBaseDescribe':$('#knowledgeBaseDescribe').val(),
				'sort':$('#sort').val(),
			},
			type: 'POST',
			async: true,
			success: function (result) {
				layer.closeAll();
				console.log('result:',result);
				if(result.code=='SUCCESS'){
					layer.msg("操作成功", {icon: 1});
					setTimeout(function(){
						window.parent.location.reload();
					}, 1000);
				}else {//失败
					layer.closeAll();
					layer.msg('不好意思，系统出现问题了，请稍后重试！', {icon: 2});
				}
			},
			error: function () {
				layer.closeAll();
				layer.msg('不好意思，系统出现问题了，请稍后重试！', {icon: 2});
			}
		});

	}

	//取消按钮
	function cancelBtn(){
		window.parent.layer.closeAll();
	}


	//数字框减少
	function phaseNumDown(){
		var nowNum = $("#sort").val();
		if( nowNum!=1 ){
			$("#sort").val( parseInt(nowNum) - 1 );
		}
	}
	//数字框增加
	function phaseNumAdd(){
		var nowNum = $("#sort").val();
		$("#sort").val( parseInt(nowNum) + 1 );
	}


</script>
</html>